package com.ktjiaoyu.crm.repository;

import com.ktjiaoyu.crm.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long> , JpaSpecificationExecutor {
    List<User> findByUsrName(String usrName);
    List<User> findByUsrNameAndUsrPassword(String usrName,String usrPassWord);
    Long countByUsrName(String usrName);

    //模糊查询
    List<User> findByUsrNameLike(String usrName);

    //注解查询
    @Query(value = "select * from sys_user where usr_role_id=?1",nativeQuery = true)
    List<User> findByRoleId(Long roleId);

    //分页查询
    @Query("select u from User u where u.usrRoleId=?1")
    Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);

}
